package com.api.google.place;

import java.util.List;

import org.apache.http.NameValuePair;

import android.content.Context;

import com.api.common.ApiHelper;
import com.api.common.BaseResponseConverter;
import com.api.common.BaseResponseListener;
import com.api.common.Constants;

public class PlaceAPIHelper extends ApiHelper{

	static public enum API_TYPE{
		NEAR_BY_SEARCH,
		TEXT_SEARCH,
	}
	
	public API_TYPE mType = null;
	
	public PlaceAPIHelper(Context context, API_TYPE type) {
		super(context);
		mType = type;
		// TODO Auto-generated constructor stub
	}

	@Override
	public String makeUrl(List<NameValuePair> parameters) {
		// TODO Auto-generated method stub
		if(parameters != null && parameters.size() > 0){
			if(mType == API_TYPE.NEAR_BY_SEARCH){
				return makeNearBySearchURL(parameters);				
			}else if(mType == API_TYPE.TEXT_SEARCH){
				return makeTextSearchURL(parameters);
			}
		} 
		return null;
	}

	@Override
	public void requestApi(String url, BaseResponseConverter converter,
			BaseResponseListener ll) {
		// TODO Auto-generated method stub
		
		requestGet(url, converter, ll);
	}

	@Override
	public boolean isCache() {
		// TODO Auto-generated method stub
		return true;
	}

	@Override
	public int getCacheTime() {
		// TODO Auto-generated method stub
		return 6000000;
	}
	
	private String makeNearBySearchURL(List<NameValuePair> parameters){
		String url = Constants.GooglePlaceAPI.PLACE_API_HOST + Constants.GooglePlaceAPI.PLACE_NEAR_BY_SEARCH;
		for(NameValuePair param : parameters){
			url += param.getName() + "=" + param.getValue() + "&";
		}
		return url + Constants.GooglePlaceAPI.PARAM_API_KEY + "=" + Constants.GooglePlaceAPI.API_KEY;
	}
	
	private String makeTextSearchURL(List<NameValuePair> parameters){
		return null;
	}
}
